package com.hmily.spring.samples.trace;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * <h1>追踪ID的配置类。</h1>
 *
 * @author hmilyylimh
 * ^_^
 * @version 0.0.1
 * ^_^
 * @date 2021-10-31
 */
@Configuration
public class TraceConfig /* extends WebMvcConfigurerAdapter*/ implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new TraceIntercepter());
    }

    @Bean
    public FilterRegistrationBean traceFilter(){
        FilterRegistrationBean bean = new FilterRegistrationBean();

        bean.setFilter(new TraceFilter());
        bean.addUrlPatterns("/*");
        bean.setName("traceFilter");
        bean.setOrder(2);

        return bean;
    }
}
